package com.zqxq.lottery.entity.o2o.order;

import com.zqxq.common.utils.BigDecimalUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.entity.po.order.OrderBetPO;
import com.zqxq.lottery.entity.vo.order.OrderBetVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:11
 */
public class OrderBetO2O {

    public static OrderBetVO toVO(OrderBetPO po) {
        if (po == null) {
            return null;
        }
        OrderBetVO orderBetVO = new OrderBetVO();
        orderBetVO.setId(DispatcherUtils.parseString(po.getId()));
        orderBetVO.setOrderId(DispatcherUtils.parseString(po.getOrder_id()));
        orderBetVO.setLotteryId(DispatcherUtils.parseString(po.getLottery_id()));
        orderBetVO.setPeriod(po.getPeriod());
        orderBetVO.setRedNum(po.getRed_num());
        orderBetVO.setBlueNum(po.getBlue_num());
        orderBetVO.setBetNum(DispatcherUtils.parseString(po.getBet_num()));
        orderBetVO.setBetTimes(DispatcherUtils.parseString(po.getBet_times()));
        BigDecimal prizeDecimal = BigDecimalUtils.getValue(po.getPrize(),2) ;
        String prize = prizeDecimal == null ? null : prizeDecimal.toPlainString();
        orderBetVO.setPrize(prize);
        BigDecimal afterTaxDecimal = BigDecimalUtils.getValue(po.getAfter_tax(),2) ;
        String afterTax = afterTaxDecimal == null ? null : afterTaxDecimal.toPlainString();
        orderBetVO.setAfterTax(afterTax);
        orderBetVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        orderBetVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return orderBetVO;
    }

    public static OrderBetPO toPO(OrderBetVO vo) {
        if (vo == null) {
            return null;
        }
        OrderBetPO orderBetPO = new OrderBetPO();
        orderBetPO.setId(DispatcherUtils.parseLong(vo.getId()));
        orderBetPO.setOrder_id(DispatcherUtils.parseLong(vo.getOrderId()));
        orderBetPO.setLottery_id(DispatcherUtils.parseLong(vo.getLotteryId()));
        orderBetPO.setPeriod(vo.getPeriod());
        orderBetPO.setRed_num(vo.getRedNum());
        orderBetPO.setBlue_num(vo.getBlueNum());
        orderBetPO.setBet_num(DispatcherUtils.parseInteger(vo.getBetNum()));
        orderBetPO.setBet_times(DispatcherUtils.parseInteger(vo.getBetTimes()));
        orderBetPO.setPrize(BigDecimalUtils.getBigDecimal(vo.getPrize()));
        orderBetPO.setAfter_tax(BigDecimalUtils.getBigDecimal(vo.getAfterTax()));
        orderBetPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        orderBetPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return orderBetPO;
    }

    public static List<OrderBetVO> toVOList(List<OrderBetPO> list){
        List<OrderBetVO> result = new ArrayList();
        if(list != null && list.size() > 0){
            for (OrderBetPO po : list){
                result.add(toVO(po));
            }
        }
        return result;
    }

}
